<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title>登录页面</title>

  <script src="/jquery-1.8.3.min.js"></script>
</head>

<body>
<form id="loginForm">
  <table>
    <tr>
      <td>用户名</td>
      <td><input type="text" id="username" /></td>
    </tr>

    <tr>
      <td>密码</td>
      <td><input type="password" id="password" /></td>
    </tr>

    <tr>
      <td>
        <button type="button" id="login">登录</button>
      </td>
      <td>
        <button type="reset">重置</button>
      </td>
    </tr>
  </table>
</form>
<script>
  $("#login").click(function () {
    let username = $("#username").val();
    let password = $("#password").val();
    $.ajax({
      url : "users/login",
      type : "post",
      async : false,
      data : {
        "username":username,
        "password":password
      },
      cache : false,
      dataType : "json",
      success : function(obj) {
        console.log(obj)
        if (obj.state=='1') {
          location.href = "/home.html";
        }
      }
    });
  });
</script>
</body>
</html>